import QtQuick 1.0


Rectangle {
    id:screen
    width: 360
    height: 640
    color: "#000000"

    Image {
        id: gaybearImage
        x: 105
        y: 114
        width: 150
        height: 143
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenterOffset: -40
        anchors.verticalCenter: parent.verticalCenter
        source: "qrc:/images/bearclaw.jpg"

        Text {
            id: digiClock
            height: 79
            color: "#ffffff"
            text: qsTr("")
            verticalAlignment: Text.AlignVCenter
            anchors.bottom: parent.bottom
            anchors.bottomMargin: -81
            wrapMode: Text.WordWrap
            transformOrigin: Item.Center
            style: Text.Raised
            font.bold: false
            font.family: "Trebuchet MS"
            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: 41
            x: 0
            y: 145
            width: 150

            property bool isColonDisplay: false

            property int lastDate: 0;
            property string lastHours;
            property string lastMin;
            property string lastAm;
        }

        Timer {
            id:clocktimer
            triggeredOnStart: true
            running: true
            repeat: true

            onTriggered: {

                var date = new Date();


                var hours = date.getHours();
                var am = "AM";
                am = hours >= 12 ? "PM" : am;
                hours = hours == 0 ? 12 : hours;
                if(hours > 12) {
                    hours -= 12;
                } else if(hours > 0 && hours < 10) {
                    hours = "0" + hours;
                }

                var min = date.getMinutes();
                if(min < 10) {
                    min = "0" + min;
                }

                dateText.text = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
                digiClock.lastDate = date.getMilliseconds();
                digiClock.lastMin = min;
                digiClock.lastHours = hours;
                digiClock.lastAm = am;


                digiClock.text = digiClock.lastHours +
                        (digiClock.isColonDisplay ? ":" : " ") + digiClock.lastMin + digiClock.lastAm;
                digiClock.isColonDisplay = !digiClock.isColonDisplay;

                // schedule timer to fire when minute hand should be moved
                clocktimer.interval = 1000*2;
            }
        }

        Text {
            id: dateText
            x: 0
            y: 213
            width: 150
            height: 56
            color: "#ffffff"
            text: qsTr("")
            horizontalAlignment: Text.AlignRight
            anchors.bottom: digiClock.top
            anchors.bottomMargin: -124
            z: 1
            verticalAlignment: Text.AlignTop
            wrapMode: Text.NoWrap
            font.pixelSize: 29
        }
    }
}
